<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('必备条件项目新增')"/>
</head>
<body>
<form action="" class="layui-form">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">编号</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" lay-verify="num" name="num" type="text">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">一级项目</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" lay-verify="firstProject" name="firstProject"
                               type="text">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">二级项目</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" lay-verify="secondProject" name="secondProject"
                               type="text">
                    </div>
                </div>


                <div class="layui-form-item" style="padding-bottom: 10px;">
                    <label class="layui-form-label" style="width: 130px">支撑文件上传</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input layui-hide" id="supportingFileId" name="supportingFileId"
                               placeholder="上传支撑文件" type="text">
                        <button class="layui-btn layui-btn-normal layui-hide" id="testList" type="button">选择文件
                        </button>
                        <button class="layui-btn layui-hide" id="testListAction" type="button">开始上传</button>
                        <button class="layui-btn layui-btn-normal" onclick="selectDocument()"
                                style="margin-right: 10px; float:left;"
                                type="button">选择文件
                        </button>
                        <span class="layui-hide" id="fileName" style="color: red"></span>
                        <div id="supportingList" style="float: left;"></div>
                        <div class="clear"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button class="layui-btn layui-btn-normal layui-btn-sm" lay-filter="infoneccessary-save" lay-submit=""
                    type="submit">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button class="layui-btn layui-btn-primary layui-btn-sm" type="reset">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<th:block th:include="include :: footer"/>
<script>
    layui.use(['form', 'jquery', 'upload'], function () {
        var form = layui.form;
        var $ = layui.jquery;
        var upload = layui.upload;


        // form.verify({
        //     rolename: function (value) {
        //         if (value.length < 2) {
        //             return '标题至少得5个字符啊';
        //         }
        //         var msg = "";
        //         $.ajax({
        //             url: rootPath + '/InfoNecessaryController/checkNameUnique',
        //             data: "name=" + value,
        //             dataType: 'json',
        //             type: 'post',
        //             async: false,
        //             success: function (result) {
        //                 msg = result;
        //             }
        //         });
        //         if (msg == 1) {
        //             return "已有相同数据";
        //         }
        //
        //     }
        // });


        form.on('submit(infoneccessary-save)', function (data) {
            console.log(data.field)
            $.ajax({
                url: rootPath + '/InfoNecessaryController/add',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (result) {
                    if (result.code == 200) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("infoNecessary-table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });

        upload.render({
            elem: '#testList'
            , url: rootPath + '/InfoNecessaryController/supportFileUpload' //改成您自己的上传接口
            , accept: 'file'
            , exts: 'pdf|jpg' //允许上传的文件类型
            , multiple: true
            , auto: false
            , bindAction: '#testListAction'
            , choose: function (obj) {
                $('#testListAction').click()
            }
            , before: function (obj) {
                this.data = {
                    'folderName': 'taskDepScore',
                };
            }
            , done: function (res, index, upload) {
                if (res.code == 0) {
                    // getSupportingList();
                    layer.msg(res.msg, {icon: 1, time: 1000});
                } else {
                    layer.msg(res.msg, {icon: 2, time: 1000});
                }
            }
            , error: function (index, upload) {
            }
        });

        //上传标志性结果佐证
        window.selectDocument = function selectDocument() {
            $('#testList').click();
        }

        // function getSupportingList() {
        //     $.ajax({
        //         url: rootPath + '/InfoNecessaryController/supportingList',
        //         dataType: 'json',
        //         type: 'post',
        //         data: {
        //             "taskscoreid": monthTaskId,
        //         },
        //         success: function (result) {
        //             var taskscoreProofList = result.taskscoreProofList;
        //             var supportingLists = '';
        //             var supportingLists2 = '';
        //             for (var i = 0; i < taskscoreProofList.length; i++) {
        //                 if (taskscoreProofList[i].evidencetype === '0') {
        //                     supportingLists += '<div id="fileName" style="float:left; line-height: 38px; margin-right: 10px;">' + taskscoreProofList[i].filename +
        //                         '<span style="width:40px; text-align:center; font-size: 12px; display:inline-block; height:30px; line-height: 30px; margin-left:10px; background: #f56c6c; color: #fff;  cursor: pointer;" onclick="delFile(\'' + taskscoreProofList[i].id + '\',\'' + taskscoreProofList[i].localpath +
        //                         '\')">删除</span><div class="clear"></div></div>';
        //                 }
        //             }
        //             $('#supportingList').html(supportingLists)
        //             $('#supportingList2').html(supportingLists2)
        //         }
        //     })
        // }
        //
        // //删除佐证
        // function delFile(id, localPath) {
        //     $.ajax({
        //         url: rootPath + '/TaskDepScoreController/delEvidence',
        //         dataType: 'json',
        //         type: 'post',
        //         data: {
        //             "id": id,
        //             "localpath": localPath
        //         },
        //         success: function (result) {
        //             if (result.code === 200) {
        //                 layer.msg(result.msg, {icon: 1, time: 1000}, function () {
        //                     getSupportingList();
        //                 });
        //             } else {
        //                 layer.msg(result.msg, {icon: 2, time: 1000});
        //             }
        //         }
        //     })
        //
        // }

    })
</script>
</body>
</html>